//
//  PropertyPayDetailCell.m
//  PropertyMananger
//
//  Created by bh on 17/3/7.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "PropertyPayDetailCell.h"
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) * 360
@implementation PropertyPayDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"PropertyPayDetailCellID";
    PropertyPayDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[PropertyPayDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
       // self.titleLabel.text = @"3月份物业费金额";
        
        self.titleLabel.textColor = BHColor(51, 51, 51);
        self.titleLabel.font = BHFont(18);
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.top.equalTo(self).with.offset(35);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
        }];
        
        UILabel * shouldLabel = [[UILabel alloc]init];
        [self.contentView addSubview:shouldLabel];
        
        shouldLabel.textAlignment = NSTextAlignmentLeft;
        shouldLabel.textColor = BHColor(102, 102, 102);
        shouldLabel.text = @"应收费";
        
        shouldLabel.font = BHFont(13);
        [shouldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(self.titleLabel.mas_bottom).with.offset(25);
            make.size.mas_equalTo(CGSizeMake(50, 25));
        }];
        
        
        self.shouldExpense = [[UILabel alloc]init];
        [self.contentView addSubview:self.shouldExpense];
        self.shouldExpense.textColor = BHColor(102, 102, 102);
        
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"10003.98 元"];
        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@" "].location);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        [self.shouldExpense setAttributedText:noteStr];
        
        self.shouldExpense.font = BHFont(15);
        self.shouldExpense.textAlignment = NSTextAlignmentLeft;
        
        [self.shouldExpense mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(shouldLabel.mas_bottom).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2 - 30, 25));
        }];
        
        UILabel * actualExpenses = [[UILabel alloc]init];
        [self.contentView addSubview:actualExpenses];
        
        actualExpenses.textAlignment = NSTextAlignmentLeft;
        actualExpenses.textColor = BHColor(102, 102, 102);
        actualExpenses.text = @"实收";
        
        actualExpenses.font = BHFont(13);
        [actualExpenses mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(self.shouldExpense.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(50, 25));
        }];
        
        self.actualExpenses = [[UILabel alloc]init];
        [self.contentView addSubview:self.actualExpenses];
        self.actualExpenses.textColor = BHColor(102, 102, 102);
        
        NSMutableAttributedString *noteStr1 = [[NSMutableAttributedString alloc] initWithString:@"4303.98 元"];
        NSRange redRange1 = NSMakeRange(0, [[noteStr1 string] rangeOfString:@" "].location);
        [noteStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange1];
        [self.actualExpenses setAttributedText:noteStr1];
        
        self.actualExpenses.font = BHFont(15);
        self.actualExpenses.textAlignment = NSTextAlignmentLeft;
        
        [self.actualExpenses mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(actualExpenses.mas_bottom).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2 - 30, 25));
        }];

        [self setupCircleView];
        
        [self createProgressFormUI];

    }
    
    return self;
}
/**
 *  初始化圆形视图
 */
- (void)setupCircleView{
    
    
    self.circleView = [[FZHDrawCircleView alloc]initWithFrame:CGRectMake(BHscreenW - 130, 50, 100, 100)];
    [self.contentView addSubview:self.circleView];
    
    self.circleView.moneyNumLabel.text = @"物业缴费";
   //    self.circleView.cateLabel.text = @"0.00";
    //2.彩色属性
    
//        self.currentNum = 200.0;//彩色的数量
//        self.totalNum = 600.0;//总比例
    
    self.circleView.colourFillColor = BHColor(65, 221, 195);//颜色
    self.circleView.normalFillColor = BHColor(221, 233, 244);
    self.circleView.colourStartAngle = 0;//起始点
    self.circleView.colourEndAngle = DEGREES_TO_RADIANS(self.currentNum/self.totalNum);
    
    
}

- (void)createProgressFormUI{

    //投诉
    UILabel * cubeLabel2 = [[UILabel alloc]init];
    [self.contentView addSubview:cubeLabel2];
    cubeLabel2.backgroundColor = BHColor(221, 233, 244);
    
    [cubeLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView).with.offset(-145);
        make.top.equalTo(self.circleView.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    self.ComfinishLab = [[UILabel alloc]init];
    [self.contentView addSubview:self.ComfinishLab];
    
    self.ComfinishLab.text = @"未完成:40单 25%";
    self.ComfinishLab.font = BHFont(13);
    self.ComfinishLab.textColor = BHColor(102, 102, 102);
    
    [self.ComfinishLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel2.mas_trailing).with.offset(5);
        make.centerY.equalTo(cubeLabel2).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
    }];
    
    UIView * lineView1 = [[UIView alloc]init];
    [self.contentView addSubview:lineView1];
    lineView1.backgroundColor = BHGrayColor;
    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.ComfinishLab).with.offset(0);
        make.top.equalTo(self.ComfinishLab.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(110, 1));
    }];
    
    
    UILabel * cubeLabel3 = [[UILabel alloc]init];
    [self.contentView addSubview:cubeLabel3];
    cubeLabel3.backgroundColor = BHColor(65, 221, 195);
    
    [cubeLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel2).with.offset(0);
        make.top.equalTo(lineView1).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    
    self.ComUnFinishLab = [[UILabel alloc]init];
    [self.contentView addSubview:self.ComUnFinishLab];
    
    self.ComUnFinishLab.text = @"已完成:140单 75%";
    self.ComUnFinishLab.font = BHFont(13);
    self.ComUnFinishLab.textColor = BHColor(102, 102, 102);
    
    [self.ComUnFinishLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel3.mas_trailing).with.offset(5);
        make.centerY.equalTo(cubeLabel3).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
    }];

}
- (void)setModel:(LeaderModel *)model{


    _model = model;
    
    if ([model.UnReceivedCost isEqualToString:model.WuYueFeeTotalCost]) {
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(0.001/600.0);
    }else if ([model.ReceivedCost isEqualToString:model.WuYueFeeTotalCost]){
    
    self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.WuYueFeeTotalCost.floatValue/model.WuYueFeeTotalCost.floatValue);
    }else{
    
     self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.ReceivedCost.floatValue/model.WuYueFeeTotalCost.floatValue);
    }
  
    
    [self.circleView setNeedsDisplay];
    
    if (![model.WuYueFeeTotalCost isEqualToString:@""]) {
        
          self.circleView.cateLabel.text = model.WuYueFeeTotalCost;
    }else{
    
     self.circleView.cateLabel.text = @"0.00";
    }
    
    if (![model.allroomCount isEqualToString:@""]) {
        
      
        //报修单
        NSString *  unFinishPercent = [NSString stringWithFormat:@"%.f%%",(model.notroomCount.floatValue/model.allroomCount.floatValue)*100];
        
        NSString * finishPercent = [NSString stringWithFormat:@"%.f%%",(model.okroomCount.floatValue/model.allroomCount.floatValue)*100];
        
        self.ComfinishLab.text = [NSString stringWithFormat:@"未缴费:%@户 %@",model.notroomCount,unFinishPercent];
        self.ComUnFinishLab.text = [NSString stringWithFormat:@"已缴费:%@户 %@",model.okroomCount,finishPercent];

        
    }else{
    
        //报修单
        NSString *  unFinishPercent = @"0%";
        
        NSString * finishPercent = @"0%";
        
        self.ComfinishLab.text = [NSString stringWithFormat:@"未缴费:0户 %@",unFinishPercent];
        self.ComUnFinishLab.text = [NSString stringWithFormat:@"已缴费:0户 %@",finishPercent];
        
    
    }

    //实收费
    if (![model.ReceivedCost isEqualToString:@""]) {
        
        NSMutableAttributedString *noteStr1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",model.ReceivedCost]];
        NSRange redRange1 = NSMakeRange(0, [[noteStr1 string] rangeOfString:@" "].location);
        [noteStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange1];
        [self.actualExpenses setAttributedText:noteStr1];
    }else{
    
        NSMutableAttributedString *noteStr1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",@"0.00"]];
        NSRange redRange1 = NSMakeRange(0, [[noteStr1 string] rangeOfString:@" "].location);
        [noteStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange1];
        [self.actualExpenses setAttributedText:noteStr1];
    }
    
    
    if (![model.WuYueFeeTotalCost isEqualToString:@""]) {
        
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",model.WuYueFeeTotalCost]];
        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@" "].location);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        [self.shouldExpense setAttributedText:noteStr];
        
        self.circleView.cateLabel.text = model.WuYueFeeTotalCost;
    }else{
        
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",@"0.00"]];
        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@" "].location);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        [self.shouldExpense setAttributedText:noteStr];
        
    }


}
@end
